// Hover effect for #search element  
const searchElement = document.getElementById("search");  

searchElement.addEventListener("mouseenter", function() {  
    searchElement.style.backgroundColor = "#0069d9";  
});  

searchElement.addEventListener("mouseleave", function() {  
    searchElement.style.backgroundColor = "#007bff";  
});  


document.getElementById("search").addEventListener("click", function() {
    var interfaceSelect = document.getElementById("interface");
    if (interfaceSelect.selectedIndex !== -1) {
      var url = interfaceSelect.options[interfaceSelect.selectedIndex].value;
      url += document.getElementById("input_box").value;
      document.getElementById("search").setAttribute("href", url);
    }

 });


// Click event for #zhuzhu element  
document.getElementById("zhuzhu").addEventListener("click", function() {  
    alert("本插件由[霜跃]开发,欢迎提交BUG!!!本插件仅用作学习!请勿商用!!!");  
});  

// Get values from chrome.storage.sync  
chrome.storage.sync.get(['default_api', 'temp_url'], function(result) {  
    if (typeof(result.default_api) !== "undefined") {  
        const defaultApiValue = result.default_api.url;  
        const optionToSelect = document.querySelector(`#interface option[value='${defaultApiValue}']`);  
        if (optionToSelect) {  
            optionToSelect.selected = true; // 设置默认选中状态  
        }  
    }  
    if (typeof(result.temp_url) !== "undefined") {  
        const hrefUrl = result.default_api.url + result.temp_url;  
        document.getElementById("input_box").value = result.temp_url; // 设置输入框的值  
        searchElement.setAttribute("href", hrefUrl); // 设置播放地址  
        searchElement.click(); // 模拟点击  
        chrome.storage.sync.remove("temp_url");  
    }  
});